<template>
 <div class="user_score pd_40">
   <div>
     <el-row :gutter="40">
      <el-col :span="7">
        <div class="fsc">
          <span class="articlelist_lable">用户名</span>
          <el-input
            placeholder="请输入"
            v-model.trim="tableData.name">
          </el-input>
        </div>
      </el-col>
      <el-col :span="7">
        <div class="fsc">
          <span class="articlelist_lable">评分时间</span>
          <el-date-picker
            v-model="tableTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="7">
        <div class="fsc">
          <span class="articlelist_lable">评分板块</span>
          <el-select v-model="tableData.spotname" placeholder="请选择">
            <el-option
              v-for="item in categories"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </div>
      </el-col>

      <!--<el-col class='mg_t20' :span="7">
        <div class="fsc">
          <span class="articlelist_lable">评分对象</span>
          <el-input
            placeholder="请输入"
            v-model="input2">
          </el-input>
        </div>
      </el-col>-->
      <el-col class='mg_t20' :span="7">
        <div class="fsc">
          <span class="articlelist_lable">评分文章</span>
          <el-input
            placeholder="请输入"
            v-model="tableData.title">
          </el-input>
        </div>
      </el-col>
     </el-row>
     <p class="articlelist_query fec">
      <el-button @click="reset">重置</el-button>
      <el-button @click="query" type="primary">查询</el-button>
    </p>
   </div>
   <div>
     <el-table
      :data="tableList"
      stripe
      style="width: 100%">
      <el-table-column
        prop="nickname"
        label="用户名"
        width="180">
      </el-table-column>
      
      <el-table-column
        prop="title"
        label="评分对象">
      </el-table-column>
      <el-table-column
        label="评分板块">
        <template slot-scope="scope">
          <span>{{isCategories(scope.row.categories_id)}}</span>
        </template>
      </el-table-column>
     
      <el-table-column
        prop="score"
        label="评分">
      </el-table-column>
      <el-table-column
        prop="commit"
        label="评论留言">
      </el-table-column>
      <el-table-column
        label="评分时间">
        <template slot-scope="scope">
          <span>{{getdates(scope.row.c_time)}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="展示状态">
        <template slot-scope="scope">
          <span>{{scope.row.is_show==1?'展示':'不允展示'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="更多用户信息">
        <template slot-scope="scope">
          <el-button @click="addsee(scope.row)" type="success" size="small">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="address"
        label="操作">
        <template slot-scope="scope">
          <el-button @click="administration(scope.row)" type="primary" size="small">管理</el-button>
        </template>
      </el-table-column>
    </el-table>
   </div>
  <div class="block fec mg_t30">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage4"
      :page-sizes="[10]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>

  <!--点击管理alert-->
  <el-dialog
    title="用户管理"
    :visible.sync="centerDialogVisible"
    width="400px"
    center>
    <div class="fbc fwrap f_13">
      <div class="user_dialog_desc fbc w100">
        <p><span>用户名:</span><span class="mg_l15">{{dialog.nickname}}</span></p>
        <p><span>评分日期:</span><span class="mg_l15">{{getdates(dialog.c_time)}}</span></p>
      </div>
      <div class="fcc mg_t30 w100 ">
        <el-button :type="index2==3?'primary':''" @click="index2=3">删除评分</el-button>
        <el-button :disabled="dialog.is_show==2?false:true" :type="index2==1?'primary':''"  @click="index2=1">恢复展示</el-button>
        <el-button :disabled="dialog.is_show==2?true:false" :type="index2==2?'primary':''"  @click="index2=2">不予公开展示</el-button>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="centerDialogVisible=false">取消</el-button>
      <el-button type="primary" size="small" @click="deletePing">确定</el-button>
    </span>
  </el-dialog>

  <!--查看用户信息alert-->
  <el-dialog
    title="更多用户信息"
    :visible.sync="moreUsermaAlert"
    width="30%"
    center>
    <div class="fbc fwrap f_13">
      <div class="fbc w100">
        <p><span>用户名:</span><span class="mg_l15">{{detail.user_info.nickname}}</span></p>
        <p class="fsc"><span>图像</span><img class="user_img mg_l15" :src="detail.user_info.headurl" alt="做客"></p>
      </div>
      <div class="user_dialog_desc fbc w100">
        <p><span>地区:</span><span class="mg_l15">{{detail.user_info.address}}</span></p>
        <p><span>年龄:</span><span class="mg_l15">{{detail.user_info.age}}</span></p>
        <p><span>身份:</span><span class="mg_l15">{{detail.user_info.expert==0?'普通':'达人'}}</span></p>
        <p><span>性别:</span><span class="mg_l15">{{detail.user_info.sex==1?'男':(detail.user_info.sex==0?'--':'女')}}</span></p>
      </div>
      <!--<div class="user_dialog_desc fbc w100">
        <p><span>姓名:</span><span class="mg_l15">刘德华</span></p>
        <p><span>身份证号码:</span><span class="mg_l15">341222199901042978</span></p>
        <p><span>电话验证:</span><span class="mg_l15">17620547902</span></p>
      </div>-->
      <div class="user_dialog_quan fbc w100">
        <p class="fcc column"><span>旅说</span><span class="mg_t10">{{detail.dynamic_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>想去看看</span><span class="mg_t10">{{detail.see_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>到此一游</span><span class="mg_t10">{{detail.visit_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>关注</span><span class="mg_t10">{{detail.follow_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>粉丝</span><span class="mg_t10">{{detail.fans_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>收藏</span><span class="mg_t10">{{detail.collection_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>评论</span><span class="mg_t10">{{detail.comment_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>评分</span><span class="mg_t10">{{detail.score_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>投诉</span><span class="mg_t10">{{detail.complain_num}}</span><span class="mg_t20 c_green">查看</span></p>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" size="small" @click="moreUsermaAlert=false;">关闭</el-button>
    </span>
  </el-dialog>
 </div>

 
</template>
<script>
export default {
  data() {
    return {
      detail: {         //详情信息
        user_info: {},
      },
      dialog: {},  //弹窗数据
      tableTime: [],
      tableData: {   //表格参数
        name: '',
        title: '',
        c_time: '',
        e_time: '',
        spotname: '',
        page:1,
      },
      getdates: this.$utils.getdates,
      total: null,
      index: 1,    //dialog里button
      index2: 1,   //dialog里button
      value: '',
      currentPage4: 1,
      centerDialogVisible: false,
      moreUsermaAlert: false,
    
      categories: [],  //版块
        
      tableList: [],  //列表

    }
  },
  created() {
    this.getList();
    this.getCategories();
  },
  watch: {
    'tableTime'(xin,jiu) {
       if(xin == null) {
        this.tableData.c_time = '';
        this.tableData.e_time = '';
      }
    }
  },
  
  methods: {
    getList() {
      let url = 'admin/grade/get_scor';
      let data = this.tableData;
      this.$request.post(url,data).then(res => {
        if(res.data.code == '0000') {
          console.log(res)
          this.tableList = res.data.data.list
          this.total = res.data.data.page.total;
          // this.detail = this.data.data
        }
      })
    },
    deletePing() {           //删除评分
      let index2 = this.index2;
      let show = index2;
      if(index2 == 3) {
        this.$confirm('是否继续删除', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let url = 'admin/grade/del_scor';
          let data = { id: this.dialog.id};
          this.$request.post(url,data).then( res => {
            if(res.data.code == '0000') {
              console.log(res)
              this.$message({
                type: 'success',
                message: '操作成功'
              })
              this.centerDialogVisible = false;
              this.getList()
            }else {
              this.$message.error('操作失败')
            }
          })
        }).catch(() => {
            this.$message.error('操作失败')   
        });
      }else {
        let url = 'admin/grade/is_show';
        let data = {id: this.dialog.id,show:show}
        this.$request.post(url,data).then( res => {
          if(res.data.code == '0000') {
            console.log(res)
            this.$message({
              type: 'success',
              message: '操作成功'
            })
            this.getList();
            this.centerDialogVisible = false
          }else {
            this.$message.error('操作失败')
          }
        })
      }
      
      
    },
    getCategories() {
      let url = '/admin/article/getCategories';
      let data = {};
      this.$request.post(url,data).then( res => {
        if(res.data.code == '0000') {
          this.categories = res.data.data
          console.log(res)
        }
      })
    },
    query() {              // 查询
      console.log(this.tableTime)
      this.currentPage4 = 1;
      this.tableData.page = 1;
      let time = this.tableTime;
      if(time instanceof Array) {
        if(time.length > 0) {
          this.tableData.c_time = Number(time[0]/1000)
          this.tableData.e_time = Number(time[1]/1000)
        }
      }
      this.getList();
    },
    administration(row) {
      console.log(row)
      this.dialog = row;
      this.index2 = 3;
      this.centerDialogVisible = true;
    },
    reset() {
      this.tableTime = [];
      this.tableData.c_time = ''
      this.tableData.e_time = ''
      this.tableData.name = ''
      this.tableData.title = ''
      this.tableData.spotname = ''
      this.currentPage4 = 1
      this.tableData.page = 1;
      this.getList();
    },  
    addsee(row) {
      console.log(row)
      let url = '/admin/user/user_info';
      let data = {user_id: row.uid};
      this.$request.post(url,data).then(res => {
        console.log(res)
        if(res.data.code == '0000') {
          this.detail = res.data.data;
          this.moreUsermaAlert = true;
        }
      })
    },
    isCategories(id) {
      if(id == 1) {
        return '景点'
      }else if(id == 2) {
        return '住宿'
      }else if(id == 3) {
        return '风味'
      }else if(id == 4) {
        return '民俗'
      }else if(id == 5) {
        return '线路'
      }else if(id == 6) {
        return '特产'
      }else if(id == 7) {
        return '人文地标'
      }
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.tableData.page = val;
      this.getList();
    },
  },
  
}
</script>
<style scoped lang="less">
  .articlelist_lable {
    min-width: 20%;
    white-space: nowrap;
  }
  .articlelist_query {
    margin-right: 100px;
    height: 100px;
  }
  .user_img {
    width: 50px;
    height: 50px;
  }
  .user_dialog_desc {
    height: 60px;
    border-bottom: 1px solid #999;
  }
  .user_dialog_quan {
    height: 100px;
  }
</style>

